package com.fdb.basic.framework.redis.redisutil;

import java.util.concurrent.TimeUnit;

/**
 * 需求编号:2019D0519
 * 问题编号:
 * 开发人员: caoxin
 * 创建日期:2019/7/17
 * 功能描述:获取redis缓存抽象类 中台的key需要新实现一个类
 * 修改日期:2019/7/17
 * 修改描述:
 */
public abstract class BasePrefix implements KeyPrefix {
    // 过期时间
    private long expireTime;
    // 过期时间单位 没有的话默认为秒
    private TimeUnit expireTimeUnit;
    // 不同的缓存的开头
    private String prefix;

    public BasePrefix(String prefix) {
        this(0, prefix);
    }

    public BasePrefix(long expireTime, String prefix) {
        this.expireTime = expireTime;
        this.prefix = prefix;
    }

    public BasePrefix(String prefix, long expireTime, TimeUnit expireTimeUnit) {
        this.expireTime = expireTime;
        this.expireTimeUnit = expireTimeUnit;
        this.prefix = prefix;
    }

    @Override
    public long expireSeconds() {
        return expireTime;
    }

    @Override
    public TimeUnit getTimeUnit() {
        return expireTimeUnit;
    }

    @Override
    public String getPrefix() {
        String className = getClass().getSimpleName();
        return className + ":" + prefix;
    }

}
